<template>
  <div class="head">
    <img class="imgIcon" src="../assets/image/headIcon.png" alt="" />
    <span class="headTitle">智慧水电智能运维系统</span>
    <div class="time">
      <div style="font-size: 1.2vw">{{ currentTime }}</div>
      <div>{{ currentDate }}</div>
    </div>
    <div class="admin">
      <span style="color: #3851e3" @click="loginOut"> 系统管理员</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import constraint from "@/data/constrant.ts";
import { useRouter } from "vue-router";

const headTitle = ref(constraint.headTitle);
const currentDate = ref("");
const currentTime = ref("");
const router = useRouter();
const updateDateTime = () => {
  const now = new Date();
  currentDate.value = now.toLocaleDateString(); // 格式化为年月日
  currentTime.value = now.toLocaleTimeString(); // 格式化为时分秒
};

onMounted(() => {
  updateDateTime();
  const interval = setInterval(updateDateTime, 1000); // 每秒更新时间

  onBeforeUnmount(() => {
    clearInterval(interval); // 清除定时器
  });
});
const loginOut = () => {
  ElMessageBox.confirm("是否退出智慧水电智能运维系统", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      ElMessage({
        type: "success",
        message: "退出成功",
      });
      router.push({ name: "Login" });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消",
      });
    });
};
</script>
<style lang="scss" scoped>
.head {
  width: 100vw;
  height: 10vh;
  /* background-image: url("src/assets/head.png"); */
  background-color: rgb(73, 154, 202);
  // display: flex;
  // align-items: center;
  // justify-content: center;
  .headTitle {
    font-size: 1.8vw;
    color: white;
    font-weight: bold;
    position: absolute;
    margin-left: 5vw;
    margin-top: 3.8vh;
  }
  .imgIcon {
    width: 3vw;
    height: 3vw;
    left: 1vw;
    position: absolute;
    margin-top: 3.4vh;
    border-radius: 50%;
  }
  .time {
    width: 8vw;
    color: #ffffff;
    position: absolute;
    margin-top: 3.2vh;
    right: 9vw;
    text-align: center;
    font-size: 1.1vw;
    // border-right: 0.1vw solid #f1eaea;
  }
  .admin {
    width: 8vw;
    color: #ffffff;
    position: absolute;
    margin-top: 4vh;
    height: 3.8vh;
    line-height: 3.8vh;
    right: 0;
    text-align: center;
    font-size: 1.2vw;
    font-weight: 550;
    // border-right: 0.1vw solid #f1eaea;
    cursor: pointer;
    border-left: 0.1vw solid #f1eaea;
  }
}
</style>
